﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.Equipment.common
{
    public partial class buyapp : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPageUserType.Add("teacher");

            NumbersTBX.Attributes.Add("readOnly", "-1");
            NameTBX.Attributes.Add("readOnly", "-1");
        }

        protected void Save_OnClick(object sender, EventArgs e)
        {
            #region 验证
            if(NumbersTBX.Text.Trim()=="")
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "分类号码不能为空!");
                return;
            }
            if(NumTBX.Text.Trim()=="")
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "购买数量不能为空!");
                return;
            }
            #endregion
            LabMS.BLL.BuyApp buyAppBLL = new LabMS.BLL.BuyApp();
            LabMS.Model.BuyApp buyAppModel = new LabMS.Model.BuyApp();

            buyAppModel.ClassNumber = NumbersTBX.Text.Trim();//分类号码
            buyAppModel.Name = NameTBX.Text.Trim();//编号名称
            if (NumbersTBX.Text.Trim() != "")
            {
                int iNum;
                if (int.TryParse(NumTBX.Text.Trim(), out iNum))
                {
                    buyAppModel.Numbers = iNum.ToString();//购买数量
                }
                else
                {
                    LabMS.Common.JShelper.JSAlert(Page, "err", "购买数量只能为不小于0整数!");
                    return;
                }
            }
            buyAppModel.Type = TypeDDL.SelectedValue;//类型
            Button btn = (Button)sender;
            string strID = btn.ID;
            if (strID == "SaveBtn")
            {
                buyAppModel.State = "0";//状态
            }
            else
            {
                buyAppModel.State = "1";//状态
                buyAppModel.AppPerson=UserRealName;
                buyAppModel.AppTime = DateTime.Now;//日期
            }

            buyAppModel.AppComment = LabMS.Common.codehelper.Encode(AppCommentTBX.Text.Trim());//申请备注
            try
            {
                buyAppBLL.Add(buyAppModel);
                LabMS.Common.JShelper.JSAlertAndRedirect(Page, "success", "添加成功!", "buyapp.aspx");
            }
            catch
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "添加失败,请重新添加!");
            } 
        }
    }
}
